package org.andes.kownledge.operator.executable;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

import org.andes.kownledge.operator.Executable;
import org.andes.kownledge.operator.Predication;
import org.andes.kownledge.operator.Term;
import org.andes.sgg.Qsolver;
import org.andes.sgg.st;

public class InWm extends Executable{
	
	Term term;
	public void setTerm(Term term){
		this.term=term;
	}
	
//	;;; precondition (in-wm <propositions>) returns a singleton set
//	;;; consisting of the given state if the proposition unifies with some
//	;;; element of working memory.  If there is no unifier, then it
//	;;; returns an empty set.  If a unifier is found, the bindings are
//	;;; added to the state.  This is just like goal-successors except that
//	;;; it doesn't call goal-successors-effects.  By passing NIL as the
//	;;; value for action-flag, it suppresses adding an action to the
//	;;; states.
//
//	(defun execute-in-wm (Ex State)
//	  "Returns a set of states, one for each unification of the given 
//	   goal with a wme." 
//	  (goal-successors-wmes (second Ex) State NIL))
	@Override
	public List<st> exec(st state) {
		List<st> result=new ArrayList<st>();
		Stack<st> temp=Qsolver.instance.goal_successors_wmes((Predication) term,state,false);
		result.addAll(temp);
		return result;
	}
}
